package org.jash.day7;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import org.jash.day7.entity.DataBean;
import org.jash.day7.entity.NewsEntity;
import org.jash.day7.mvp.BaseFragment;
import org.jash.day7.utils.ConStruct;
import org.jash.day7.utils.NewsPresenter;

import java.util.List;


public class NewsFragment extends BaseFragment<ConStruct.INewsView, NewsPresenter> implements ConStruct.INewsView {
    private RecyclerView recycler;
    private NewsAdapter adapter = new NewsAdapter();

    @Override
    protected int layoutId() {
        return R.layout.fragment_news;
    }

    @Override
    protected void initData() {
        presenter = new NewsPresenter();
        presenter.loadTopHot();

    }

    @Override
    protected void initView() {
        recycler = getView().findViewById(R.id.recycler);
        recycler.setAdapter(adapter);
    }

    @Override
    public void success(List<DataBean> list) {
        adapter.addAll(list);
    }

    @Override
    public void failure(Throwable t) {
        Toast.makeText(requireContext(), t.getMessage(), Toast.LENGTH_SHORT).show();
    }
}